Add simple test app to test pow-24 accuracy
authorAlexander Larsson <alexl@redhat.com>
Mon, 18 Jun 2012 13:17:51 +0000 (15:17 +0200)
committerØyvind Kolås <pippin@gimp.org>
Fri, 27 Jul 2012 19:04:58 +0000 (21:04 +0200)
https://bugzilla.gnome.org/show_bug.cgi?id=678318

babl/base/Makefile.am
babl/base/test-pow.c [new file with mode: 0644]

index 5b92521970b9676518233be302683c18c809b525..58f711e9ecc655eb989440097b02548542a0d0bb 100644 (file)
@@ -27,3 +27,7 @@ EXTRA_DIST =          \
        util.h  \
        pow-24.h
 
+noinst_PROGRAMS = test-pow
+
+test_pow_SOURCES = test-pow.c
+test_pow_LDADD = libbase.la $(MATH_LIB)
diff --git a/babl/base/test-pow.c b/babl/base/test-pow.c
new file mode 100644 (file)
index 0000000..08406c9
--- /dev/null
@@ -0,0 +1,54 @@
+#include <stdio.h>
+#include <math.h>
+
+#include "pow-24.h"
+
+int
+main (int argc, char *argv[])
+{
+  double s, r1, r2, diff, max;
+  double at_s, at_r1, at_r2;
+  long i;
+
+  s = 0.03;
+  at_s = 0;
+  max = 0;
+  for (i = 0; i < 1100000000; i++)
+    {
+      r1 = babl_pow_24 (s);
+      r2 = pow (s, 2.4);
+      diff = fabs (r2-r1);
+      if (diff > max) {
+       max = diff;
+       at_s = s;
+       at_r1 = r1;
+       at_r2 = r2;
+      }
+      s += 0.000000001;
+    }
+  printf ("x^2.4\n");
+  printf ("max from 0 to %f is %e\n", s, max);
+  printf ("at: %f %f %f\n", at_s, at_r1, at_r2);
+
+  s = 0.03;
+  at_s = 0;
+  max = 0;
+  for (i = 0; i < 1100000000; i++)
+    {
+      r1 = babl_pow_1_24 (s);
+      r2 = pow (s, 1/2.4);
+      diff = fabs (r2-r1);
+      if (diff > max) {
+       max = diff;
+       at_s = s;
+       at_r1 = r1;
+       at_r2 = r2;
+      }
+      s += 0.000000001;
+    }
+  printf ("x^(1/2.4)\n");
+  printf ("max from 0 to %f is %e\n", s, max);
+  printf ("at: %f %f %f\n", at_s, at_r1, at_r2);
+
+  return 0;
+}